package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.entity.GoodsType;
import com.example.service.GoodsTypeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 宠物用品类型 controller 层
 */
@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Resource
    private GoodsTypeService goodsTypeService;

    @PostMapping("/add")
    public Result add(@RequestBody GoodsType goodsType) {
        this.goodsTypeService.add(goodsType);
        return Result.success();
    }

    @GetMapping("/pageQuery")
    public Result pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            GoodsType goodsType
    ) {
        PageResult<GoodsType> pageResult = this.goodsTypeService.pageQuery(pageNum, pageSize, goodsType);
        return Result.success(pageResult);
    }

    @GetMapping("/query")
    public Result queryById(@RequestParam Integer id) {
        GoodsType goodsType = this.goodsTypeService.queryById(id);
        return Result.success(goodsType);
    }

    @GetMapping("/query/all")
    public Result queryAll() {
        List<GoodsType> goodsTypeList = this.goodsTypeService.queryAll();
        return Result.success(goodsTypeList);
    }

    @PutMapping("/update")
    public Result update(@RequestBody GoodsType goodsType) {
        this.goodsTypeService.update(goodsType);
        return Result.success();
    }


    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        this.goodsTypeService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.goodsTypeService.deleteBatch(ids);
        return Result.success();
    }
}
